
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/api';
import { TaskMenuService } from './taskmenu.service';

@Component({
  templateUrl: './taskmenu-group.component.html',
  styleUrls: ['./taskmenu-group.component.scss'],
  providers: [TaskMenuService]
})
export class TaskMenuGroupComponent implements OnInit {
  menuGroupForm: FormGroup;
  menuGroup: any = {};
  systemUrl: string ;
  constructor(
    private fb: FormBuilder,
    private ref: DynamicDialogRef,
    private config: DynamicDialogConfig,
    private taskMenuService: TaskMenuService) {
    this.systemUrl= this.config.data.systemUrl;
    this.menuGroup.groupId = this.config.data.groupId;
    this.menuGroup.groupName = this.config.data.groupName;
  }

  ngOnInit() {
    this.buildForm();
  }
  /**新增 */
  save() {
    let menuGroup = this.menuGroupForm.value;
    this.taskMenuService.saveUpdateGroup(menuGroup, this.systemUrl).subscribe(data => {
      this.ref.close(data);
    });
  }

  /**取消关闭窗口 */
  cancel() {
    this.ref.close();
  }

  buildForm(): void {
    this.menuGroupForm = this.fb.group({
      'groupId': [this.menuGroup.groupId],
      'groupName': [this.menuGroup.groupName, Validators.required]
    });
  };
}